package com.css.fxfzaqbz.modules.estimate.repository.impl;

import com.css.fxfzaqbz.modules.estimate.entity.Fault;
import com.css.fxfzaqbz.modules.estimate.entity.StratumLithology;
import com.css.fxfzaqbz.modules.estimate.entity.StrongCatalog;
import com.css.fxfzaqbz.modules.estimate.repository.StratumLithologyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class StratumLithologyRepositoryImpl implements StratumLithologyRepository {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    @Override
    public void batchSave(List<StrongCatalog> list4) {
        SqlParameterSource[] beanSources = SqlParameterSourceUtils.createBatch(list4.toArray());
        String sql = "INSERT INTO sys_stratum_lithology(id, stratigraphy_name, years, sedimentary_facies, thickness, main_name, main_symbol, description, union_stratum, symbol_main, symbolup, symbollow, comment_info, geom, source_flag, del_flag, data_version, create_user, create_time, update_user, update_time, jsl_code, province, city, county, town, extends1, extends2, extends3, extends4, extends5, extends6, extends7, extends8, extends9, extends10, colorid, main_code, values1, result_analysis) values(:id, :stratigraphyName, :years, :sedimentaryFacies, :thickness, :mainName, :mainSymbol, :description, :unionStratum, :symbolMain, :symbolup, :symbollow, :commentInfo, ST_GeometryFromText(:geom, 4490), :sourceFlag, :delFlag, :dataVersion, :createUser, :createTime, :updateUser, :updateTime, :jslCode, :province, :city, :county, :town, :extends1, :extends2, :extends3, :extends4, :extends5, :extends6, :extends7, :extends8, :extends9, :extends10, :colorid, :mainCode, :values1, :resultAnalysis)";
        namedParameterJdbcTemplate.batchUpdate(sql, beanSources);
    }

    @Override
    public List<StratumLithology> getList(String resultAnalysis) {
        String sql = "select *,ST_AsText(geom) geom from sys_stratum_lithology where result_analysis = '" + resultAnalysis + "'";
        List<StratumLithology> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(StratumLithology.class));
        return list;
    }
}
